//abnormal.js
const app = getApp();
Page({
  data: {
    abnormalGroupList: [{
      id: 0,
      name: "中国平安",
      code: "601318.SH",
      rate: 0.0845,
      newsList: [0, 1, 2].map((index) => {
        return {
          id: index.toString(),
          title: "IMF：垃圾债的繁荣意味着什么？",
          abstract: `在信贷繁荣中，如果垃圾债的份额不断上升，那么接下来三到四年里，经济增长将放缓。`,
          content: `在信贷繁荣中，如果垃圾债的份额不断上升，那么接下来三到四年里，经济增长将放缓。`,
          pictureSource: 'https://wpimg.wallstcn.com/f0548e3c-4d89-4ffc-8f8c-de7afc23fd35.png?imageView2/1/w/720/h/540',
          timestamp: new Date().getTime() + 24 * 60 * 60 * 1000 * (Math.random() * 2 - 1),
        };
      })
    }, {
      id: 1,
      name: "广汽集团",
      code: "601238.SH",
      rate: -0.0602,
      newsList: [0, 1, 2, 4, 5].map((index) => {
        return {
          id: index.toString(),
          title: "IMF：垃圾债的繁荣意味着什么？",
          abstract: `在信贷繁荣中，如果垃圾债的份额不断上升，那么接下来三到四年里，经济增长将放缓。`,
          content: `在信贷繁荣中，如果垃圾债的份额不断上升，那么接下来三到四年里，经济增长将放缓。`,
          pictureSource: 'https://wpimg.wallstcn.com/f0548e3c-4d89-4ffc-8f8c-de7afc23fd35.png?imageView2/1/w/720/h/540',
          timestamp: new Date().getTime() + 24 * 60 * 60 * 1000 * (Math.random() * 2 - 1),
        };
      })
    }],
    showNewsIndex: null,
    userInfo: {},
    subNaviBarItems: ["异动", "首页", "用户"].map(a => ({
      name: a,
      iconSrc: "/svg/clock.svg"
    })),
    currentActivePageIndex: 0,

  },
  gotoIndexPage: function () {
    wx.redirectTo({
      url: '../index/index'
    })
  },
  onSubNaviBarItemTapped: function (e) {
    console.log(e.detail, 'tapped');
    if (e.detail === 1) {
      this.gotoIndexPage();
    }
  },
  onNewsTapped: function (e) {
    console.log(e);
    const newsId = e.target.dataset.newsId;
    const newsList = this.data.newsList;
    const newsIndex = newsList.findIndex(item => item.id === newsId);
    this.setData({
      showNewsIndex: newsIndex
    });
  },
  onModalCloseButtonTapped: function (e) {
    this.setData({
      showNewsIndex: null
    });
  },
  onLoad: function () {
    var that = this;
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
      that.update()
    })
  }
})